import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import path from 'path'
import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { VantResolver } from '@vant/auto-import-resolver'

// https://vite.dev/config/
export default defineConfig({
  server: {
    open: true,
    port: 8088,
    proxy: {
      '/api': {
        target: 'http://localhost:8080', // 后端实际地址（不带/api）
        changeOrigin: true,
        rewrite: path => path.replace(/^\/api/, '/api') // 保持路径不变
        // 或者如果后端不需要/api前缀：
        // rewrite: path => path.replace(/^\/api/, '')
      }
    }
  },
  resolve: {
    alias: {
      '@': path.resolve(__dirname, 'src')
    }
  },
  plugins: [
    vue(),
    AutoImport({
      resolvers: [VantResolver()]
    }),
    Components({
      resolvers: [VantResolver()]
    })
  ]
})
